<?php

/* @var $this yii\web\View */

?>
<div>
    <?= '分类/创建分类' ?>
    <br/><hr class="hr-solid"/><br/>
    <form id="form-create" class="form-dev" method="post" action="/dev/category/ajaxcreate">
        <input type="text" name="name" placeholder="名称" class="editor" autocomplete="off"/><br/><br/>
        <input type="text" name="desc" placeholder="描述" class="editor" autocomplete="off"/><br/><br/>
        <input type="submit" value="创建分类" class="btn"/><br/>
    </form>
    <br/>
    <p id="p-result"></p>
</div>

<?php $this->beginBlock('work') ?>
    $().ready(function() {
        $(document).ready(function() {
            var opts = {
                beforeSubmit: function(formData, $jqForm, options) {
                    $('#p-result').html('');
                    var inputSubmit = $jqForm.find("input[type='submit']");
                    if(inputSubmit.hasClass("btn-disable")) {
                        return false;
                    }
                    $jqForm.find("input[type='submit']").addClass("btn-disable").attr("value", "创建中");
                    return true;
                },
                success: function(respTxt, statusTxt, xhr, $jqForm) {
                    $jqForm.find("input[type='submit']").removeClass("btn-disable").attr("value", "创建分类");
                    $jqForm.resetForm();

                    var resp_obj = JSON.parse(respTxt);
                    if(0 === resp_obj.code) {
                        $('#p-result').html('创建成功');
                    } else {
                        $('#p-result').html('failed: ' + resp_obj.msg);
                    }
                }
            };
            $('#form-create').ajaxForm(opts);
        });
    });
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['work'], \yii\web\View::POS_END); ?>

